import Vue from 'vue'
import VueRouter from 'vue-router'



Vue.use(VueRouter)




const router = new VueRouter({
  routes: [
    // 当路由为 / 时，跳转到 login 页面
    {
      path: '/', name: 'Login', component: () => import('@/views/LoginAndError/Login.vue'),
      meta: {
        keepAlive: false,
        title: "登录页"
      }
    },
    {
      path: '/401', name: '401', component: () => import('@/views/LoginAndError/401.vue'),
      meta: {
        keepAlive: false,
        title: "错误信息"
      }
    },
    {
      path: '/404', name: '404', component: () => import('@/views/LoginAndError/404.vue'),
      meta: {
        keepAlive: false,
        title: "无信息"
      }
    },
    // 信息页面
    {
      path: '/main', name: 'Main', redirect: 'index', component: () => import('@/views/Main.vue'),
      meta: {
        keepAlive: false,
        title: "窗口页"
      },
      children: [
        // 首页 开始 ===================
        {
          path: '/index', name: 'Index', component: () => import('@/views/LoginAndError/index.vue'),
          meta: {
            keepAlive: false,
            title: "首页"
          }
        },
        // 首页 结束 ===================
        {
          path: '/menulist', name: 'MenuList', component: () => import('@/views/HomePage/poweranage/menu'),
          meta: {
            keepAlive: false,
            title: "菜单管理"
          }
        },
        {
          path: '/rolelist', name: 'RoleList', component: () => import('@/views/HomePage/poweranage/role'),
          meta: {
            keepAlive: false,
            title: "角色管理"
          }
        },
        {
          path: '/userlist', name: 'UserList', component: () => import('@/views/HomePage/poweranage/user'),
          meta: {
            keepAlive: false,
            title: "用户管理"
          }
        },
        {
          path: '/dictionarylist', name: 'DictionaryList', component: () => import('@/views/HomePage/poweranage/dictionary'),
          meta: {
            keepAlive: false,
            title: "字典管理"
          },
        },
        {
          path: '/dictionary_children_list', name: 'DictionaryChildrenList', component: () => import('@/views/HomePage/poweranage/dictionary/indexcopy.vue'),
          meta: {
            keepAlive: false,
            title: "字典信息"
          },
        },
        {
          path: '/log_list', name: 'LogList', component: () => import('@/views/HomePage/poweranage/log'),
          meta: {
            keepAlive: false,
            title: "登录日志"
          },
        },
        {
          path: '/log_cz_list', name: 'LogCzList', component: () => import('@/views/HomePage/poweranage/log/indexcopy.vue'),
          meta: {
            keepAlive: false,
            title: "操作日志"
          },
        },
        {
          path: '/express', name: 'Express', component: () => import('@/views/HomePage/poweranage/express'),
          meta: {
            keepAlive: false,
            title: "物流管理"
          }
        },
        {
          path: '/store', name: 'Store', component: () => import('@/views/HomePage/poweranage/store'),
          meta: {
            keepAlive: false,
            title: "物流管理"
          }
        },
      ],
    },
  ],
})


// function lastary(router){
//   console.log(router,123)
//   // return router
// }
// lastary(router)

//先把VueRouter原型对象的push保存一份
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}



//======= 路由守卫
router.beforeEach((to, from, next) => {
  let path = to.redirectedFrom || to.path;
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next();
});


export default router
